package com.example.common;

import java.util.HashMap;
import java.util.Map;

public class Result {
    /* 业务层面的成功 */
    private static final Integer SUCCESS = 200;
    /* 业务层面的失败，比如校验不通过、操作失败... */
    private static final Integer ERROR = 500;

    public static Map<String, Object> success(String msg) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", SUCCESS);
        result.put("msg", msg);
        return result;
    }

    public static Map<String, Object> success(Object data) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", SUCCESS);
        result.put("data", data);
        return result;
    }

    public static Map<String, Object> error(String msg) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", ERROR);
        result.put("msg", msg);
        return result;
    }
}
